package com.base.mine;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.base.commonlib.base.CBaseBarMvpActivity;
import com.base.commonlib.sp.SpUtil;
import com.base.mine.databinding.ActivityChangepwBinding;
import com.base.mine.databinding.ActivityForgetPwdBinding;
import com.base.mine.presenter.ChangePwPresenter;
import com.base.mine.presenter.ForgetPwdPresenter;
import com.base.mine.view.ChangePwView;
import com.base.mine.view.ForgetPwdView;

/**
 * Created by zw on 2020/5/02.
 */

@Route(path = "/forgetpw/pw")
public class ForgetPwActivity extends CBaseBarMvpActivity<ForgetPwdPresenter> implements ForgetPwdView {
    @Autowired
    int type;
    private ActivityForgetPwdBinding mBinding;
    @Override
    protected int getLayoutResource() {
        return R.layout.activity_forget_pwd;
    }

    @Override
    protected void init() {
        super.init();
        mBinding = (ActivityForgetPwdBinding) mRootBinding;
        mPresenter = new ForgetPwdPresenter(this,this);
        mPresenter.start();
        setBackNavigation();
        setBarTitle("重置密码");

    }

    @Override
    protected void start() {
        if (!TextUtils.isEmpty(SpUtil.getUserAccount())){
            mBinding.forgetInputPhone.setText(SpUtil.getUserAccount());
        }else {
            mBinding.forgetInputPhone.setHint("请输入手机号");
        }
        mBinding.forgetInputPhone.setSelection(mBinding.forgetInputPhone.getText().length());

        mBinding.sendCode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mBinding.sendCode.getText().equals("发送验证码")){
                    if (TextUtils.isEmpty(mBinding.forgetInputPhone.getText().toString())){
                        showMes("请输入手机号码");
                        return;
                    }else {
                        mPresenter.SendCode(mBinding.forgetInputPhone.getText().toString());
                    }
                }else {
                    showMes("验证码已发送");
                    return;
                }
            }
        });
        mBinding.sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (TextUtils.isEmpty(mBinding.forgetInputPhone.getText().toString())){
                    showMes("手机号不能为空");
                    return;
                }
                if (TextUtils.isEmpty(mBinding.loginInputCode.getText().toString())){
                    showMes("验证码不能为空");
                    return;
                }
                if (TextUtils.isEmpty(mBinding.newpw.getText().toString())){
                    showMes("新密码不能为空");
                    return;
                }

                if (TextUtils.isEmpty(mBinding.ensurepw.getText().toString())){
                    showMes("确认密码不能为空");
                    return;
                }
                if (!mBinding.ensurepw.getText().toString().equals(mBinding.newpw.getText().toString())){
                    showMes("两次密码不一致");
                    return;
                }

                mPresenter.updatePwdByPhone(mBinding.forgetInputPhone.getText().toString(),mBinding.loginInputCode.getText().toString(),mBinding.newpw.getText().toString());
            }
        });
    }

    @Override
    public TextView returnSendCodeView() {
        return mBinding.sendCode;
    }
}
